-module(shopcart).
-author("daqing15@163.com").

-export([cost/1, total/1, sum/1]).

cost(oranges)	->5;
cost(newspaper) ->8;
cost(apples)	->9;
cost(pears)		->2;
cost(milk)		->7.

%% Buy1 = [{oranges, 4}, {newspaper, 6}, {apples, 22}]
total([{What,N}|T]) -> cost(What) * N + total(T);
total([])			-> 0.


sum(L) -> sum(L, 0).

sum([], N) -> N;
sum([H|T], N) -> sum(T, H + N).

